import dayjs from 'dayjs'
import colors from './colors'

/**
 *
 * @param {*} start 相识的日期
 * @param {*} count 计算几个100天
 * @returns
 */
export const dateList = (start = new Date(), count = 10) => {
  let list = []
  start = dayjs(start).startOf('date').format('YYYY-MM-DD')
  let colorList = getColor(count)

  let m = start
  for (let i = 1; i < count; i++) {
    m = dayjs(m).add(100 * 24, 'hour').format('YYYY-MM-DD')

    list.push({
      number: i * 100,
      date: m,
      textColor: colorList[i]
    })
  }

  console.log(list)
  return list
}

function getColor(count) {
  count = count || Math.floor(colors.length / 2)
  let result = []

  let random = () => {
    let t1 = Math.floor(Math.random() * colors.length)
    let c1 = colors[t1]
    // 删除数组
    colors.splice(t1, 1)
    let t2 = Math.floor(Math.random() * colors.length)
    let c2 = colors[t2]

    result.push([c1,c2])
    count--

    if (count !== 0) {
      random()
    }
  }

  random()


  return result
}
